package com.candy.test;

import com.candy.service.AccountService;
import com.candy.service.impl.AccountServiceImpl;
import com.candy.service.impl.AccountServiceImpl2;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Client {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
////        ApplicationContext ac=new FileSystemXmlApplicationContext("C:\\Users\\Administrator\\Desktop\\applicationContext.xml");
        AccountService accountService=ac.getBean("accountService", AccountServiceImpl2.class);
//        AccountService accountService1=(AccountService) ac.getBean("accountService");
        accountService.saveAccount();
    }
    public static void test02( ) {
//        AccountService accountService=new AccountServiceImpl();
//        accountService.saveAccount();
//ApplicationContext的三个常用实现类：
//ClassPathXmlApplicationContext：它可以加载类路径下的配置文件，要求配置文件必须在类路径下。不在的话，加载不了。(更常用)
//FileSystemXmlApplicationContext：它可以加载磁盘任意路径下的配置文件(必须有访问权限）
//AnnotationConfigApplicationContext：它是用于读取注解创建容器的
        ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
////        ApplicationContext ac=new FileSystemXmlApplicationContext("C:\\Users\\Administrator\\Desktop\\applicationContext.xml");
        AccountService accountService=ac.getBean("AccountService", AccountServiceImpl.class);
        AccountService accountService1=(AccountService) ac.getBean("AccountService");
        System.out.println(accountService==accountService1);
        System.out.println(accountService);
        ac.close();

//        AccountDao accountDao=(AccountDao) ac.getBean("AccountDao");
//        System.out.println(accountDao);

//        Resource resource = new ClassPathResource("applicationContext.xml");
//        BeanFactory factory = new XmlBeanFactory(resource);
//        AccountService as  = (AccountService)factory.getBean("AccountService");
//        System.out.println(as);


    }
}
